
// import axios from "axios";

 // 全局默认配置
 axios.defaults.baseURL = ' http://121.43.116.41/demo/php/';
 axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';


// 此写法直接调用axios.get/post方法  => 发送请求 

/*  axios.get("/searchGradeOrderLimit.php", { params: this.searchParams }).then(response => {
    if (response.status == 200) {
        return response.data;
    } else {
        var err = new Error("Request Fail!")
        throw err;
    }
})

axios.post("/updateGradeById.php", {
    id: item.id,
    ch: item.chinese,
    mh: item.math,
    eh: item.english
}).then(response => {
    if (response.status == 200) {
        return response.data;
    } else {
        var err = new Error("Request Fail!")
        throw err;
    }
})

axios.get("/deleteGradeById.php", { params: { id: id } }).then(response => {
    if (response.status == 200) {
        return response.data;
    } else {
        var err = new Error("Request Fail!")
        throw err;
    }
}) */


// 将所以的请求整合到一起  => 方便后期管理
// 封装成函数  => 提前定义好请求方式  请求地址  => 数据需要再函数调用时传入(传入对象数据)

export function searchGradeOrderLimitAPI(params){
    return axios.get("/searchGradeOrderLimit.php", { params: params }).then(response => {
        if (response.status == 200) {  // 后端返回响应数据  
            return response.data;
        } else { // 其他情况
            var err = new Error("Request Fail!")
            throw err;
        }
    })  // 返回Promise实例 => 默认pending状态, 请求成功之后会携带响应数据data, 请求失败会抛出错误
}


export function updateGradeByIdAPI(data){
    return axios.post("/updateGradeById.php", data).then(response => {
        if (response.status == 200) {
            return response.data;
        } else {
            var err = new Error("Request Fail!")
            throw err;
        }
    })
}

export function deleteGradeByIdAPI(params){
    return axios.get("/deleteGradeById.php", { params: params }).then(response => {
        if (response.status == 200) {
            return response.data;
        } else {
            var err = new Error("Request Fail!")
            throw err;
        }
    })
}